package com.ljx.rabbit.controller;


import com.ljx.rabbit.domain.po.Banner;
import com.ljx.rabbit.domain.po.HeadGoods;
import com.ljx.rabbit.domain.po.Hot;
import com.ljx.rabbit.domain.vo.BannerVo;
import com.ljx.rabbit.domain.vo.CategoryHead;
import com.ljx.rabbit.domain.vo.HomeGoods;
import com.ljx.rabbit.result.R;
import com.ljx.rabbit.service.IBannerService;
import com.ljx.rabbit.service.ICategoryService;
import com.ljx.rabbit.service.IHotService;
import com.ljx.rabbit.service.IItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 轮播图 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-01-20
 */
@RestController
@RequestMapping("/home")
@Api(tags = "首页")
@RequiredArgsConstructor
@CrossOrigin
public class HomeController {
    private final IBannerService bannerService;
    private final IHotService hotService;
    private final ICategoryService categoryService;
    private final IItemService itemService;
    @ApiOperation(value = "轮播图")
    @GetMapping("/banner")
    public R<List<BannerVo>> getBanner(@RequestParam(required = false) Integer distributionSite){
        if(distributionSite==null)
            distributionSite=1;
        List<BannerVo> list=bannerService.listByDistributionSite(distributionSite);
        return R.success(list);
    }
    @ApiOperation(value = "人气推荐")
    @GetMapping("/hot")
    public R<List<Hot>> getHot(){
        List<Hot> list=hotService.list();
        return R.success(list);
    }

    @ApiOperation(value = "获取全部分类，包含推荐商品")
    @GetMapping("/category/head")
    public R<List<CategoryHead>> getCategoryHead(){
        List<CategoryHead> list=categoryService.getCategoryHead();
        return R.success(list);
    }

    @ApiOperation(value = "获取新鲜好物")
    @GetMapping("/new")
    public R<List<HeadGoods>> getNewGoods(@RequestParam(required = false) Integer limit){
        if (limit==null)
            limit=4;
        List<HeadGoods> list=itemService.getNewGoods(limit);
        return R.success(list);
    }

    @ApiOperation(value = "获取首页商品")
    @GetMapping("/goods")
    public R<List<HomeGoods>> getGoods(@RequestParam(required = false) Integer limit){
        if (limit==null)
            limit=4;
        List<HomeGoods> list=categoryService.getHomeGoods(limit);
        return R.success(list);
    }
}
